/**
 * Copyright (c) 2011 Tomi Paananen.
 *
 * Part of Quick Gestures user interface.
 */

#ifndef GESTUREHELPER_H
#define GESTUREHELPER_H

// Qt includes
#include <QObject>
#include <QString>
#include <QUrl>

// Forward declarations
class FeatureExtractor;
class Gesture;
class GestureModel;
class GestureProcessor;
class QuickGesturesEngine;


class GestureHelper : public QObject
{
    Q_OBJECT
    Q_PROPERTY(int modifiedGesturesCount READ modifiedGesturesCount NOTIFY modifiedGesturesCountChanged)
    Q_PROPERTY(bool autoProcess READ autoProcess WRITE setAutoProcess NOTIFY autoProcessChanged)

public:
    explicit GestureHelper(QObject *parent = 0);
    virtual ~GestureHelper();

public:
    int modifiedGesturesCount() const;
    bool autoProcess() const;
    void setAutoProcess(bool autoProcess);

public:
    Q_INVOKABLE bool copy(Gesture *src, Gesture *dest) const;
    Q_INVOKABLE bool update(Gesture *gesture, GestureModel *model) const;
    Q_INVOKABLE bool copyAndAppend(Gesture *gesture, GestureModel *model) const;
    Q_INVOKABLE bool process(Gesture *gesture, GestureModel *model) const;
    Q_INVOKABLE bool isModified(quint32 id) const;
    Q_INVOKABLE QString extractFilenameFromPath(const QString &path) const;
    Q_INVOKABLE QString removeFileFromPath(const QString &path) const;
    Q_INVOKABLE QString urlToLocalFile(const QUrl &url) const;
    Q_INVOKABLE QUrl ensurePathValidity(const QUrl &path) const;

public slots:
    void setModified(quint32 id);
    void clearModifiedGestures();
    void saveGestures(const QUrl &path, QuickGesturesEngine *engine);
    void center(Gesture *gesture, int width, int height);

signals:
    void modified(quint32 id);
    void modifiedGesturesCountChanged(int count);
    void autoProcessChanged(bool autoProcess);

private: // Data
    FeatureExtractor *m_featureExtractor; // Owned
    GestureProcessor *m_processor; // Owned
    QList<quint32> m_idsOfModifiedGestures;
    bool m_autoProcess;
};

#endif // GESTUREHELPER_H

// End of file.
